package com.lebang.medicalInquiry.task;

import com.lebang.medicalInquiry.mapper.PhysicianMapper;
import com.lebang.medicalInquiry.model.po.Physician;
import com.lebang.medicalInquiry.utils.DigitalMataHttpUtil;
import com.lebang.medicalInquiry.utils.TextUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@Component
@EnableAsync
@EnableScheduling
public class MedicalTask {

    @Value("${digital.merchant_id}")
    private String merchantId;

    @Resource
    private PhysicianMapper physicianMapper;

    @Scheduled(cron = "0 * * * * ? ")
    public void getDyData() {
        final List<Physician> allEnable = physicianMapper.getAll();
        final List<Physician> collect = allEnable.stream().filter((s) -> s.getIsLive() == 1).collect(Collectors.toList());
        collect.forEach(s -> {
            final String liveRoomId = s.getLiveRoomId();
            if (!TextUtil.isEmpty(liveRoomId)) {
                DigitalMataHttpUtil.liveHearbeat(s.getProjectId(), merchantId, s.getLiveRoomId(), "");
            }
        });
    }
}
